package com.lzh.mybatisdemo.utils;

import cn.hutool.core.lang.UUID;
import com.lzh.mybatisdemo.entity.Country;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.BeanWrapper;
import org.springframework.beans.BeanWrapperImpl;

import java.beans.PropertyDescriptor;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.*;
import java.util.regex.Pattern;

/**
 * @Author wanchonglang
 * @description
 * @Date 2022/4/10 14:44
 */
public class CopyUtils {

    public static void copyNullProperties(Object source, Object target) {
        BeanUtils.copyProperties(source, target, getNullField(source));
    }

    private static String[] getNullField(Object target) {
        BeanWrapper beanWrapper = new BeanWrapperImpl(target);
        PropertyDescriptor[] propertyDescriptors = beanWrapper.getPropertyDescriptors();
        Set<String> notNullFieldSet = new HashSet<>();
        if (propertyDescriptors.length > 0) {
            for (PropertyDescriptor p : propertyDescriptors) {
                String name = p.getName();
                Object value = beanWrapper.getPropertyValue(name);
                if (Objects.isNull(value)) {
                    notNullFieldSet.add(name);
                }
            }
        }
        String[] notNullField = new String[notNullFieldSet.size()];
        return notNullFieldSet.toArray(notNullField);
    }

    public static void main(String[] args) {
//        boolean matches = Pattern.matches("^.{0,5}$", "1234");
//        System.out.println("matches = " + matches);
//        Long num = 123L;
//        System.out.println(num.toString());
//        boolean matches1 = Pattern.matches("^\\d{0,2}$", String.valueOf(num));
//        System.out.println(matches1);

//        String str = "A1B2C3";
//        boolean matches1 = Pattern.matches("^[A-Za-z0-9]+$", str);
//        System.out.println(matches1);
//
//        List<String> list = new ArrayList<>();
//        list.add("1");
//        list.add("2");
//        list.add("3");
//        System.out.println("list = " + list);
//        list.removeAll(list);
//        System.out.println("list = " + list);
//        List<String> strArr = Arrays.asList("21", "22", "3", "4");
//
//        strArr.stream().filter(str -> {
//            return str.startsWith("2");
//        }).filter(str -> {
//            return str.equals("22");
//        }).forEach(str -> {
//            str = "10";
//        });
//
//        String test = "file.txt";
//        String substring = test.substring(0, test.lastIndexOf("."));
//        System.out.println("substring = " + substring);

//        Optional.ofNullable(mapper.loadById(spec)).orElseGet(CompanyInfo::new);
//        for (int i = 0; i < 3; i++) {
//            Country country = new Country();
//            country.setId((long) i);
//            country.setCountryCode("1");
//            country.setCountryName("Test");
//            List<Country> strings = Lists.newArrayList(country);
//            System.out.println("strings = " + strings);

//            @Accessors(chain=true)
//            可以链式set值
//            Object obj = new Ojbect();
//            obj.setA().setB().setC();
//            注解设置为chain=true，生成setter方法返回this（也就是返回的是对象），代替了默认的返回void.
//        String str = "MULTILINESTRING ((47.627820809063095 86.49866142479695, 47.63088365256504 86.50248080710242, 47.633639718018756 86.50780712277269, 47.63746379622674 86.513448874798, 47.64107645307613 86.5157982267009, 47.65532162186475 86.51550382553368, 47.67064090549793 86.51308429208524, 47.681899093428825 86.51209469722825, 47.70016655993568 86.512514008267, 47.71013215186748 86.51432349625236, 47.718391787210756 86.51416621955414, 47.73824067007714 86.51475863173351, 47.7481757710835 86.51474674405856, 47.764852981149325 86.51561023641094, 47.77244068781971 86.51502941902206, 47.77936976939487 86.517378775994, 47.78462257862751 86.51958312801301, 47.79175835906394 86.52034988441348, 47.80605067518369 86.51790942189017, 47.81818416293214 86.5075124807467, 47.82950506706691 86.4988669594952, 47.83634454740054 86.49238290650213, 47.840876922812534 86.4840940997059, 47.84543256620641 86.47763032182456, 47.86340812331659 86.4683445840341, 47.8765241022895 86.46560600155445, 47.88167834563685 86.46539290838463, 47.88865983673445 86.46650390354418, 47.89202500621427 86.47015351981022, 47.894010056901124 86.47755245828155, 47.89311468641907 86.48513993758937, 47.889379220707546 86.49321295740357, 47.88666135397888 86.50436542733543, 47.8858671662305 86.5143718543609, 47.887573816793726 86.52612648223119, 47.89143129304595 86.53850958754356, 47.894372614993706 86.54533720934504, 47.90061932604386 86.56103335909023, 47.90687645018321 86.57764794333897, 47.91270724029505 86.5974403593053, 47.91534722212803 86.6068012187534, 47.92171588572024 86.61941506144899, 47.925115247943104 86.62826254677672, 47.931818691771724 86.63864605649209, 47.944048800810506 86.64934024195558, 47.956136418753566 86.64661452105675, 47.960714099982916 86.64351528514277, 47.96575717386719 86.64242733846578, 47.97288930542756 86.64474150012302, 47.97955583792073 86.64993984693677, 47.98632121087667 86.657561566446, 47.99301185734515 86.66459286550726, 48.00282963234852 86.67749975656116, 48.009195816927196 86.68033566300414, 48.014864247678176 86.68091566286095, 48.01851832480861 86.68358413368114, 48.02454800297869 86.68865824466369, 48.028699819463334 86.69363961019656, 48.03079457892122 86.7004140531675, 48.03234563065992 86.70611343166496, 48.03493180175129 86.71183318252648, 48.03639161239107 86.71357519870585, 48.03971974934354 86.71694702160991, 48.04591351029929 86.71677453803274, 48.051186595224564 86.71256528748879, 48.05752481566146 86.70530334318786, 48.063401467346154 86.70092590295617, 48.07601785200594 86.6998988872396, 48.08803174427351 86.70149082459913, 48.09731963598709 86.7044488963256, 48.10504127174638 86.70814701807983, 48.11466581202276 86.7137742361119, 48.12187155269371 86.71669528046652, 48.12666570373652 86.72181492761186, 48.142781746009085 86.73210009304465, 48.149947250665285 86.73963861373225, 48.15512838106907 86.74619115268956, 48.16036436561485 86.75487549160503, 48.16413161645337 86.75844322476263, 48.16878541039356 86.7608453587305, 48.176423871954576 86.76058639129022, 48.18208606187802 86.75780055975001, 48.1980437352837 86.75770775160707, 48.20374025437094 86.76013245170454, 48.20849359993836 86.76496651788142, 48.21156704037241 86.77210439470782, 48.21396754306868 86.78464959598254, 48.21559477352757 86.79433736162984, 48.216435606502905 86.80270454457799, 48.218657134280775 86.80885134863748, 48.223082718311446 86.81439362422933, 48.23042057924558 86.81668021026924, 48.239577127674416 86.81693247200408, 48.261975845683914 86.81693139547284, 48.280918029583056 86.82494899911511, 48.29178197284928 86.83057511386801, 48.300182891492845 86.83472853387003, 48.307758757451474 86.83726151314518, 48.31820201054376 86.84116358650074, 48.32806744116371 86.84707150007205, 48.33847170633122 86.85313838112745, 48.34095979116686 86.85645625793859, 48.34405216277805 86.85960847258099, 48.347910688515775 86.86562708078262, 48.3516546216799 86.86737052461835, 48.355740703942175 86.86686679017997, 48.36165111903073 86.86432496103065, 48.36740889808698 86.8605930939713, 48.37318951158957 86.85869996656973, 48.37815471906127 86.85857058562222, 48.383411785735326 86.86082273395398, 48.39091770644369 86.87108031989146, 48.395752134923924 86.87991629643645, 48.40193999757007 86.90131363717813, 48.40430835209149 86.91790827674163, 48.406820891992965 86.93815861257023, 48.41130843931216 86.94924851598222, 48.41836719395235 86.9593335660709, 48.42436012050075 86.96416578795441, 48.43439371037924 86.97313438922062, 48.442635732478216 86.98105218394784, 48.45837614032531 86.99340107633792, 48.468767941165474 86.99858377692064, 48.47738709704202 87.00116827146314, 48.480498653598204 87.0061763822, 48.48378925251445 87.01267828011557, 48.48741141352033 87.01847409295188, 48.49024387293556 87.02294246841028, 48.494847820781445 87.02662271619099, 48.499799029240734 87.02805089187741, 48.506753341604224 87.02893468702409, 48.51707492859535 87.03013746047424, 48.53162394892566 87.03450870232413, 48.5376840428367 87.03317033570674, 48.54590083983494 87.03247821172593, 48.55656331574179 87.02803620186408, 48.564126051072556 87.02536145751523, 48.573239661294004 87.0234990350616, 48.57829802042446 87.02582526471349, 48.5852992787443 87.03379687196498, 48.588558121719046 87.04340545658552, 48.59266596279775 87.05401900310787, 48.596959193867654 87.05686585843699, 48.603775037447136 87.05655736487402, 48.60905253799905 87.05388763168972, 48.61620956069799 87.04792772523781, 48.619112002420195 87.04281572765393, 48.62302056336555 87.03742948025814, 48.62826204337974 87.03445934262571, 48.63591687227447 87.03422837830279, 48.64174606481062 87.03604010806427, 48.64764656336564 87.03505238098327, 48.65958024737427 87.02315246045245, 48.66216660734232 87.01379406758225, 48.66722844465262 86.99418033331165, 48.6689284199777 86.98104450682904, 48.67322641781966 86.96874292669939, 48.67822497300319 86.95872216253846, 48.68666092989376 86.94126512102862, 48.6925608155122 86.93099235282668, 48.700331146156515 86.91989532546698, 48.70721092322522 86.91336930041821, 48.71104396025507 86.91077181089001, 48.71756646851423 86.90805538461953, 48.725951786999794 86.90699094535681, 48.73458876462986 86.91297566998985, 48.74222272423094 86.91923682589105, 48.7453052257204 86.92736617481349, 48.74759078431651 86.93911888628699, 48.750192963329816 86.94676194222222, 48.75415542121261 86.95527166222205, 48.75801595704466 86.95792837828085, 48.76486127196195 86.95698320817588, 48.770489336004914 86.95544247764389, 48.77440388361419 86.95684826440765, 48.77781142127201 86.96086886887048, 48.77973778441994 86.96808171617064, 48.78148818468991 86.97720106227662, 48.78271676866532 86.98212744168252, 48.78604606195259 86.98555184392934, 48.79127832321195 86.98752776398806, 48.799123139233835 86.98879005838612, 48.81159608493712 86.9887881170919, 48.83055562892756 86.99506707297778, 48.836813529398185 86.99862486987223, 48.843382557441856 86.99961855278418, 48.84744537890721 87.00222648349101, 48.85172915975162 87.0100438133353, 48.85396883641016 87.01810912600025, 48.853299779558235 87.02789942061347, 48.851861154056024 87.03479921676342, 48.85325577460951 87.04278624324294, 48.855547079789204 87.04959982987366, 48.85853165888226 87.05529443444661, 48.86380031809622 87.06098889669369, 48.87248521511354 87.06823124805987, 48.87803200373014 87.07447042571414, 48.88439953468456 87.08575873811516, 48.888777456144396 87.09603873740511, 48.89252762085291 87.10463084541553, 48.89643056523895 87.11783233406172, 48.89758129517286 87.13240364204043, 48.89776603523046 87.15436631624671, 48.8959824904848 87.16787170913315, 48.89692846903626 87.17908611433637, 48.899948755149396 87.18508988053155, 48.904976427853185 87.19055120911369, 48.91309772509944 87.19579567895308, 48.91937037751439 87.20123333117719, 48.92540604130668 87.20642326968192, 48.932337196847286 87.21385637842344, 48.9387190029522 87.22019601411837, 48.95449133473688 87.2379645384776, 48.96723969275457 87.24538390782958, 48.97571535186965 87.24495974279466, 48.98495730729859 87.24401732943176, 48.99150804810036 87.24318018713154, 49.00236236147829 87.24180231322302, 49.00876571766477 87.24317956086102, 49.01290032507527 87.24641042123383, 49.019305520720664 87.25896623892174, 49.02183992213581 87.27474310054858, 49.02556590537519 87.28150311019229, 49.03173076782775 87.28605443937516, 49.03877849998162 87.28757312021091, 49.049797895595226 87.28926366092668, 49.062241703073596 87.29243803200086, 49.084251701737216 87.29987422576248, 49.09858424628029 87.30316486209328, 49.107832518646276 87.30222856712383, 49.11358954002684 87.30273919880014, 49.11445441839461 87.30265250401168))";
//        String str1 = str.substring(str.indexOf("(")+1,str.indexOf(")")+1);
//        System.out.println("split = " + str1);
//
//        List<String> titleText = new ArrayList<>();
//        titleText.add("截至目前累计完成污水治理的行政村数(个)(自动计算)");
//        titleText.add("农村生活污水治理率(%)(自动计算)");
//        titleText.add("设施正常运行率(%)");
//        titleText.add("截至目前累计完成整治的水体数(个)(自动计算)");
//        titleText.add("国家监督农村黑臭水体整治率(%)(自动计算)");
//        titleText.add("公开网址");
//        System.out.println(titleText.contains("公开网址"));
    }
}

